import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import 'package:state_manage/infinite_list/post.dart';

/// 文章的状态
@immutable
abstract class InfiniteState extends Equatable {
  const InfiniteState();
  @override
  List<Object> get props => [];
}

/// 文章初始化状态
class PostUninitialized extends InfiniteState {}

/// 文章异常状态
class PostError extends InfiniteState {}

/// 有文章需要加载
class PostLoaded extends InfiniteState {
  /// 文章列表
  final List<Post> posts;

  /// 是否还有更多文章
  final bool hasReachedMax;

  const PostLoaded({this.posts, this.hasReachedMax});

  /// 拷贝对象
  /// @param post 文章列表
  /// @param hasReachMax 是否还有更多文章
  PostLoaded copyWith({List<Post> posts, bool hasReachedMax}) {
    return PostLoaded(
        posts: posts ?? this.posts,
        hasReachedMax: hasReachedMax ?? this.hasReachedMax);
  }

  @override
  List<Object> get props => [posts, hasReachedMax];

  @override
  String toString() =>
      "PostLoaded { posts: ${posts.length}, hasReachedMax: $hasReachedMax }";
}
